package com.baozun.houji.me.widget

import android.content.Context
import android.view.View
import com.baozhun.mall.common.model.enums.Sex
import com.baozhun.mall.common.widget.dialog.BaseBottomPopupView
import com.baozun.houji.me.R
import com.baozun.houji.me.databinding.DialogSexChooseBinding
import com.lxj.xpopupext.adapter.ArrayWheelAdapter

/**
 * @Title：性别选择弹框
 * @Description：
 * @Author：xing.luo
 * @Since：2022/12/2
 * @Version：1.0.0
 */
class SexChooseDialog(context: Context, private val sex: Int?, private var selectBack: (sex: Int) -> Unit) :
    BaseBottomPopupView<DialogSexChooseBinding>(context) {

    var mSelectSexType = Sex.MAN.tag
    private val mSexData = arrayListOf(Sex.MAN.sexDesc, Sex.WOMEN.sexDesc)

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_sex_choose
    }

    override fun onCreate() {
        super.onCreate()
        mBinding.sexWheelView.adapter = ArrayWheelAdapter(mSexData)
        mBinding.sexWheelView.currentItem = mSexData.indexOf(if (sex == Sex.MAN.tag) Sex.MAN.sexDesc else Sex.WOMEN.sexDesc)
        mBinding.sexWheelView.setCyclic(false)
        mBinding.sexWheelView.setOnItemSelectedListener {
            mSelectSexType = if (mSexData[it] == Sex.MAN.sexDesc) Sex.MAN.tag else Sex.WOMEN.tag
        }
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v?.id) {
            R.id.btnCancel -> dismiss()
            R.id.btnConfirm -> {
                dismiss()
                selectBack.invoke(mSelectSexType)
            }
        }
    }
}